package zhongbo.java.air.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.Topic;
import zhongbo.java.air.listener.RedisSubscribeLogChannelListener;

// RedisListenerConfig.java
@Configuration
@Slf4j
public class RedisListenerConfig {
    public static String LOG_CHANGE = "injesthd_flight_path";
    public static String INST_FLIGHT_PATH = "live_flight_path_[lgh]";
    /**
     * 配置redis 监听器，添加logChannelListener监听器到容器里，同时指定channel名称为log_chanel
     *
     * @param listenerContainer Redis消息监听容器
     * @param logChannelListener Redis消息监听器
     */
    @Autowired
    public void configListener(RedisMessageListenerContainer listenerContainer,
                               RedisSubscribeLogChannelListener logChannelListener) {
        log.info("配置redis监听器");
        Topic logTopic = new PatternTopic(LOG_CHANGE);
        listenerContainer.addMessageListener(logChannelListener, logTopic);
        // 添加对 INST_FLIGHT_PATH 频道的监听
        Topic instFlightPathTopic = new PatternTopic(INST_FLIGHT_PATH);
        listenerContainer.addMessageListener(logChannelListener, instFlightPathTopic);
    }
}
